package com.hundun.hddeal.config;

import com.hundun.hddeal.interceptor.AdUserLoginInterceptor;
import com.hundun.hddeal.interceptor.CorsInterceptor;
import com.hundun.hddeal.interceptor.MtUserLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义拦截器
 * @author
 * @date
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

  // 拦截所有请求

      @Override
      public void addInterceptors(InterceptorRegistry registry){

          InterceptorRegistration ir = registry.addInterceptor(corsLoginInterceptor());
          ir.addPathPatterns("/**"); // 所有跨域请求
//          InterceptorRegistration ir1 = registry.addInterceptor(adUserLoginInterceptor());
//          ir1.addPathPatterns("/ad/**")//拦截除登陆注册所有请求
//                  .excludePathPatterns("/ad/login")
//                  .excludePathPatterns("/ad/register");
//          InterceptorRegistration ir2 = registry.addInterceptor(mtUserLoginInterceptor());
//          ir2.addPathPatterns("/mt/**")//拦截除登陆注册所有请求
//                  .excludePathPatterns("/mt/login")
//                  .excludePathPatterns("/mt/register");
      }


    @Bean
    public CorsInterceptor corsLoginInterceptor() {
        return new CorsInterceptor();
    }
   /* @Bean
    public AdUserLoginInterceptor adUserLoginInterceptor() {
        return new AdUserLoginInterceptor();
    }

    @Bean
    public MtUserLoginInterceptor mtUserLoginInterceptor() {
        return new MtUserLoginInterceptor();
    }*/
}
